<template>
    <div class="navigation_bar_contaienr" :style="{
        color: color,
        backgroundColor: backgroundColor,
        fontSize: fontSize + 'px',
        height: height + 'px',
    }">
        <img v-if="isImage" class="navigation_bar_icon" src="" />

        <div class="btn" @click="clickMenu">+</div>

        <div class="navigation_bar_group" :style="{
            marginLeft: interval + 'px',
            backgroundColor: backgroundColor,
        }">
            <div :class="['navigation_bar_group_item', active ? 'active' : '']"
                v-for="navigationBarItem in navigationBarList" :key="navigationBarItem.title">
                <div class="navigation_bar_group_item_text" :style="{
                    lineHeight: (+height / 2) + 'px'
                }">{{ navigationBarItem.title }}</div>

                <div class="navigation_bar_group_children" :style="{
                    backgroundColor: backgroundColor,
                }">
                    <div v-for="item in navigationBarItem.children" :key="item.title"
                        class="navigation_bar_group_children_item">
                        {{ item.title }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, computed } from 'vue';

const props = defineProps({
    color: {
        type: String,
        default: '#333333'
    },
    backgroundColor: {
        type: String,
        default: '#ffffff'
    },
    hoverBackgroundColor: {
        type: String,
        default: '#eeeeee'
    },
    fontSize: {
        type: String,
        default: '14',
    },
    height: {
        type: String,
        default: '120'
    },
    interval: {
        type: String,
        default: '150'
    },
    isImage: {
        type: Boolean,
        default: true
    }
})

const navigationBarList = ref([
    {
        title: '导航1',
        children: [
            {
                title: '子导航',
            }
        ]
    },
    {
        title: '导航2',
        children: [
            {
                title: '子导航',
            }
        ]
    },
    {
        title: '导航3',
        children: [
            {
                title: '子导航1',
            },
            {
                title: '子导航2',
            },
            {
                title: '子导航3',
            },
            {
                title: '子导航4',
            },
        ]
    },
    {
        title: '导航4',
        children: [
            {
                title: '子导航',
            }
        ]
    },
    {
        title: '导航5',
        children: [
            {
                title: '子导航',
            }
        ]
    },
    {
        title: '导航6',
        children: [
            {
                title: '子导航',
            }
        ]
    },
    {
        title: '导航7',
        children: [
            {
                title: '子导航',
            }
        ]
    },
])

const clickMenu = () => {
    active.value = !active.value;
}

const active = ref(false)

const hoverHeight = computed(() => {
    return (props.height / 2) + 'px';
})
const hoverBackground = computed(() => {
    return props.hoverBackgroundColor;
})
</script>

<style lang="scss" scoped>
.navigation_bar_contaienr {
    display: flex;
    align-items: center;
    justify-content: space-between;

    @media screen and (max-width: 512px) {
        padding: 0 30px;
        width: calc(100% - 60px);
        height: 50px !important;
        position: relative;

        .navigation_bar_icon {
            width: 40%;
            height: 80%;
        }

        .navigation_bar_group {
            margin: 0 !important;
            position: absolute;
            width: calc(100% - 30px);
            padding: 0 0 0 30px;
            left: 0;
            top: 100%;
            z-index: 99;
            transition: all 0.3s;

            .navigation_bar_group_item {
                flex: 1;
                word-break: keep-all;
                white-space: nowrap;
                margin: 0 20px 0 0;
                transition: all 0.3s;
                height: 0px;
                overflow: hidden;

                .navigation_bar_group_item_text {
                    line-height: 40px !important;
                }

                .navigation_bar_group_children {
                    display: none;
                }
            }

            .active {
                height: 40px;
                line-height: 40px;
                border-bottom: 1px solid rgba(255, 255, 255, 0.5);
            }
        }

        .btn {
            font-size: 24px;
        }
    }

    @media screen and (min-width: 513px) and (max-width: 1024px) {
        padding: 0 7.5%;
        width: 85%;
        position: relative;

        .navigation_bar_icon {
            width: 30%;
            height: 60%;
        }

        .navigation_bar_group {
            margin: 0 !important;
            position: absolute;
            width: calc(100% - 30px);
            padding: 0 0 0 30px;
            left: 0;
            top: 100%;
            z-index: 99;
            transition: all 0.3s;

            .navigation_bar_group_item {
                flex: 1;
                word-break: keep-all;
                white-space: nowrap;
                margin: 0 20px 0 0;
                transition: all 0.3s;
                height: 0px;
                overflow: hidden;

                .navigation_bar_group_item_text {
                    line-height: 40px !important;
                }

                .navigation_bar_group_children {
                    display: none;
                }
            }

            .active {
                height: 40px;
                line-height: 40px;
                border-bottom: 1px solid rgba(255, 255, 255, 0.5);
            }
        }

        .btn {
            font-size: 24px;
        }
    }

    @media screen and (min-width: 1025px) {
        padding: 0 17.5%;
        width: 65%;

        .navigation_bar_icon {
            width: 25%;
            height: 50%;
        }

        .navigation_bar_group {
            flex: 1;
            height: 50%;
            display: flex;
            justify-content: space-between;

            .navigation_bar_group_item {
                flex: 1;
                text-align: center;
                cursor: pointer;
                position: relative;
                height: 100%;

                &:hover {
                    transition: all 0.5s;

                    .navigation_bar_group_item_text {
                        background-color: v-bind(hoverBackground);
                    }

                    .navigation_bar_group_children {
                        .navigation_bar_group_children_item {
                            line-height: v-bind(hoverHeight);
                            height: v-bind(hoverHeight);
                        }
                    }
                }

                .navigation_bar_group_item_text {
                    height: 100%;
                    width: 100%;
                    transition: all 0.5s;
                    position: relative;
                }

                .navigation_bar_group_children {
                    position: absolute;
                    width: 100%;
                    z-index: 999;

                    .navigation_bar_group_children_item {
                        transition: all 0.5s;
                        height: 0px;
                        width: 100%;
                        overflow: hidden;

                        &:hover {
                            background-color: v-bind(hoverBackground);
                        }
                    }
                }
            }
        }

        .btn {
            display: none;
        }
    }
}
</style>